package com.fanfutian.eventproject.service.impl;

import com.fanfutian.eventproject.mapper.CategoryMapper;
import com.fanfutian.eventproject.pojo.Category;
import com.fanfutian.eventproject.service.CategoryService;
import com.fanfutian.eventproject.utils.ThreadLocalUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Slf4j
@Service
public class CategoryServiceImpl implements CategoryService {


    @Autowired
    private CategoryMapper categoryMapper;


    /**
     * 添加分类
     * @param category
     */
    @Override
    public void addCategory(Category category) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        // 设置创建人ID
        category.setCreateUser(userId);
        categoryMapper.addCategory(category);
    }


    /**
     * 获取分类列表
     * @return
     */
    @Override
    public List<Category> getCategoryList() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        log.info("当前用户ID为：{}",userId);
        return categoryMapper.getCategoryList(userId);
    }


    /**
     * 获取分类详情
     * @param id
     * @return
     */
    @Override
    public Category detail(Integer id) {
        Category category = categoryMapper.detail(id);
        log.info("分类详情信息··········{}",category);
        return category;
    }


    /**
     * 更新文章分类
     * @param category
     */
    @Override
    public void updateCategoryInfo(Category category) {
        log.info("更新ID为 {} 的文章信息",category.getId());
        categoryMapper.updateCategoryInfo(category);
    }


    /**
     * 删除文章分类
     * @param id
     */
    @Override
    public void deleteCategoryInfo(Integer id) {
        categoryMapper.deleteCategoryInfo(id);
    }
}
